package com.azt.front.action.freemarker;

import com.azt.api.pojo.Content;
import com.azt.api.service.ContentService;
import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @ClassName RecommendContentDirective
 * @Description 获取推荐资讯的模板
 * @author Snowler
 * @Date 2016年8月5日 下午4:28:02
 * @version 1.0.0
 */
@Component("recommend_content")
public class RecommendContentDirective implements TemplateDirectiveModel {
	
	
	@Autowired
	private ContentService cs;

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
			throws TemplateException, IOException {
		Integer num = DirectiveUtils.getInt("num", params, 5);
		List<Content> recommendContents = cs.getRecommendContents(num);
		DirectiveUtils.writerBean(recommendContents, env, params, body);
	}

}
